#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<ctime>
using namespace std;
const int maxn=100010;
string dir[2*maxn];
template<class T>
struct Treap
{
	int C,Top,bin[maxn];
	int L[maxn],R[maxn],P[maxn],pri[maxn],size[maxn];
	T key[maxn];
	int root;
	void init()
	{
		srand(time(0));
		root=0;
		C=0;
		Top=0;
		memset(L,0,sizeof(L));
		memset(R,0,sizeof(R));
		memset(P,0,sizeof(P));
	}
	void rightRotate(int x)
	{
		int y=L[x];
		L[x]=R[y];
		if(R[y])P[R[y]]=x;
		P[y]=P[x];
		if(!P[x])root=y;
		else if(x==L[P[x]])
			L[P[x]]=y;
		else R[P[x]]=y;
		R[y]=x;
		P[x]=y;
	}
	void leftRotate(int x)
	{
		int y=R[x];
		R[x]=L[y];
		if(L[y])P[L[y]]=x;
		P[y]=P[x];
		if(!P[x])root=y;
		else if(x==L[P[x]])L[P[x]]=y;
		else R[P[x]]=y;
		L[y]=x;
		P[x]=y;
	}
	int min(int x)
	{
		while(L[x])x=L[x];
		return x;
	}
	int max(int x)
	{
		while(R[x])x=R[x];
		return x;
	}
	int next(int x)
	{
		if(R[x])return min(R[x]);
		int y=P[x];
		while(y&&x==R[y])
		{
			x=y;
			y=P[y];
		}
		return y;
	}
	int pre(int x)
	{
		if(L[x])return max(L[x]);
		int y=P[x];
		while(y&&x==L[y])
		{
			x=y;
			y=P[y];
		}
		return y;
	}
	void makeSize(int x)
	{
		if(!L[x]&&!R[x])size[x]=1;
		else
		{
			if(L[x])makeSize(L[x]);
			if(R[x])makeSize(R[x]);
			size[x]=1;
			if(L[x])size[x]+=size[L[x]];
			if(R[x])size[x]+=size[R[x]];
		}
	}
	void keepSize(int x)
	{
		while(x)
		{
			size[x]=1;
			if(L[x])size[x]+=size[L[x]];
			if(R[x])size[x]+=size[R[x]];
			x=P[x];
		}
	}
	int insert(T k)
	{
		int z;
		if(Top) z=bin[--Top];
		else
		{
			z=++C;
			pri[z]=rand();
		}
		L[z]=R[z]=P[z]=0;
		key[z]=k;
		int x=root,y=0;
		while(x)
		{
			y=x;
			if(k<key[x])x=L[x];
			else x=R[x];
		}
		P[z]=y;
		if(!y)root=z;
		else if(k<key[y])L[y]=z;
		else R[y]=z;
		while(P[z]&&pri[z]<pri[P[z]])
		{
			if(z==L[P[z]])rightRotate(P[z]);
			else leftRotate(P[z]);
		}
		if(!P[z])root=z;
		makeSize(z);
		keepSize(P[z]);
		return z;
	}
	int search(T& k)
	{
		int x=root;
		while(x&&!(key[x]==k))
		{
			if(k<key[x])x=L[x];
			else x=R[x];
		}
		return x;
	}
};
int main()
{
	Treap<string>treap;
	treap.init();
	char a[30],b[15],c[15];
	while(gets(a)&&a[0]!='\0')
	{
		sscanf(a,"%s%s",&b,&c);
		string s1(b);
		string s2(c);		
		treap.insert(s2);
		int x=treap.search(s2);
		dir[x]=s1;
	}
	string str;
	while(getline(cin,str))
	{
		if(str[0]=='\000')break;
		int x=treap.search(str);
		if(x!=0)cout<<dir[x]<<endl;
		else printf("eh\n");
		//cout<<str<<endl;
	}
	return 0;
}


	


